package com.spzx.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spzx.product.domain.ProductSku;
import com.spzx.product.domain.SkuPrice;
import com.spzx.product.mapper.ProductSkuMapper;
import com.spzx.product.service.ProductSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, ProductSku> implements ProductSkuService {
    @Autowired
    ProductSkuMapper productSkuMapper;

    @Override
    public List<SkuPrice> selectAllSkuPrice(List<Long> skuIdList) {
        List<ProductSku> productSkus = productSkuMapper.selectList(
                new LambdaQueryWrapper<ProductSku>().in(ProductSku::getId, skuIdList)
                        .select(ProductSku::getId,ProductSku::getSalePrice));
        return productSkus.stream().map(item->
                {
                    SkuPrice skuPrice = new SkuPrice();
                    skuPrice.setSkuId(item.getId());
                    skuPrice.setSalePrice(item.getSalePrice());
                    return skuPrice;
                }

        ).collect(Collectors.toList());
    }
}
